package bootstrap

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
	"os"
	"text/template"
)

type shGenerator interface {
	genBootstrapScript()
}

type envParam struct {
	ignore_fabric_ca_download bool
	ignore_fabric_download    bool
	fabric_version            string
	fabric_ca_version         string
}

var tplPath = "templates/bin_file_url.tpl"

func getTemplate() *template.Template {
	t, err := template.ParseFiles(tplPath)
	if err != nil {
		log.Fatalln("读取文件"+tplPath+"发生错误", err)
	}
	return t
}
func GenBootstrapScript() {
	tpl := getTemplate()
	info := envParam{
		ignore_fabric_ca_download: false,
		ignore_fabric_download:    false,
		fabric_version:            "2.3.1",
		fabric_ca_version:         "1.4.9",
	}
	var info2 = envParam{false, false,
		"2.3.1", "1.4.9"}
	fmt.Println(info2.ignore_fabric_download)
	var err = tpl.Execute(os.Stdout, info)
	if err != nil {
		log.Fatal("Execute error:", err)
	}
	println("输出")
}

func Gen(c *gin.Context) {
	GenBootstrapScript()
	//du := &utils.DownloadUtil{
	//	Url: "https://hyperledger-fabric.readthedocs.io/en/release-2.2/_images/hyperledger_fabric_logo_color.png",
	//	Filename: "gopher.png",
	//}
	//du.Download2browser(c)
}
